/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.sml.SEFM.BUS;

import java.util.Iterator;
import java.util.List;
import javax.persistence.RollbackException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.SystemException;
import vn.com.sml.SEFM.DAO.MerchantDAO;
import vn.com.sml.SEFM.domain.Merchant;
/**
 *
 * @author Tunp
 */
public class MerchantBUS {
        
    public static Integer saveDvcnt(Merchant Dvcnt) throws SecurityException, RollbackException, HeuristicRollbackException, HeuristicMixedException, IllegalStateException, SystemException {
        return MerchantDAO.saveDvcnt(Dvcnt);
    }
   
    public static List<Merchant> listDvcnt() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException{
        return MerchantDAO.listDvcnts();
    }

    public Merchant getDvcntById(int id) throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        List<Merchant> lstDm = MerchantDAO.listDvcnts();
        if(lstDm.isEmpty())
            return null;
        for (Iterator<Merchant> it = lstDm.iterator(); it.hasNext();) {
            Merchant Dvcnt = it.next();
            if(Dvcnt.getMerchantId() == id)
                return Dvcnt;
        }
        return null;
    }

    public Merchant getDvcntByMerchant(String merchantcode) {
        return MerchantDAO.getDvcntByMerchant(merchantcode);
    }
}
